
const mongoose = require('mongoose');
const config = require('./config');

module.exports = function () {
  //连接mongodb数据库
  mongoose.connect(config.mongodb);
  // 实例化连接对象
  var db = mongoose.connection;
  db.on('error', console.error.bind(console, '连接错误：'));
  db.once('open', function(callback) {
    console.log('MongoDB连接成功！！');
    return db;
  })
};
